package com.zgscwjm.taobaphelper.auto;

import android.content.Context;
import android.provider.Settings;
import android.telephony.TelephonyManager;

import com.zgscwjm.taobaphelper.exutils.StringUtils;

/**
 * Created by zgscwjm on 17-3-9.
 * 对应原来的a类
 */
public class phoneBaseInfo {
    static phoneBaseInfo a = new phoneBaseInfo();


    private phoneBaseInfo() {
    }


    public static phoneBaseInfo a() {
        return a;
    }

    /**
     * 获取系统唯一标示 对应原来的a方法
     * @param context
     * @return
     */
    public static String getDeviceId(Context context) {
        return ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId();
    }


    /**
     * 对应原来的b方法
     * @param context
     * @return
     */
    public static String getPhoneNumber(Context context) {
        String phoneNumber = Settings.System.getString(context.getContentResolver(), "phone_number");
        if (phoneNumber == null || phoneNumber.length() <= 7) {
            phoneNumber = ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getLine1Number();
            if (phoneNumber == null || phoneNumber == StringUtils.EMPTY) {
                phoneNumber = "########";
            }
            Settings.System.putString(context.getContentResolver(), "phone_number", phoneNumber);
        }
        return phoneNumber;
    }
}
